/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assisisw.smartcal.webuisubsystem.managedbean.validator;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Francesco
 */
@ManagedBean ( name = "userNameSignUpValidator" )
public class UserNameSignUpValidator extends AbstractUserNameValidator implements Serializable
{

    // Static Fields
    
    /***/
    private static final FacesMessage usernameNotExistentException = new FacesMessage ( "Sorry, but this mail address doesn't exist..." ) ; 
    
    /***/
    private static final FacesMessage usernameAlreadyUsedMesasge = new FacesMessage ( "Already used by another !" ) ;
    
    // Instance Methods
    
    /***/
    public UserNameSignUpValidator () {}

    /**
     * AS THE SUPER'S ONE.
     */
    @Override
    protected void specificValidation ( String mail ) throws ValidatorException 
    {
        if ( getUserController ().isRegistered ( mail) ) 
            throw new ValidatorException ( usernameAlreadyUsedMesasge ) ;
        else
            if ( ! getMailVerifier ().exists ( mail ) )
                throw new ValidatorException ( usernameNotExistentException ) ;
    }
    
}
